package com.demo.spring_demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    //首页的访问配置(注意一点必须要导入thymeleaf依赖具体什么原因不知道！)
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("login");
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/index.html").setViewName("index");

        registry.addViewController("/front/index.html").setViewName("user");
        registry.addViewController("/register_html.html").setViewName("register_html");
        registry.addViewController("/forgotPassword.html").setViewName("forgotPassword");
    }

    //自定义的国家化视图组件加载生效!
    @Bean
    public LocaleResolver localeResolver() {
        return new MyLocaleResolver();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加拦截器
//        registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**") //拦截
//                .excludePathPatterns("/login", "/", "/login.html","/backed/**","/login/**","/register.html","/register_html"); //不拦截
    }
}
